package cn.edu.lzu.unitweb.controller;

import cn.edu.lzu.common.assist.DataPage;
import cn.edu.lzu.common.assist.ResponseResult;
import cn.edu.lzu.entity.Examiner;
import cn.edu.lzu.entity.SpeculumExamineItem;
import cn.edu.lzu.service.SpeculumExamineItemService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.support.DefaultSubjectContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @PackageName: cn.edu.lzu.unitweb.controller
 * @ClassName: SpeculumExamineItemController
 * @Description: TODO
 * @Author: 张琦[QQ:3098086691]
 * @Date: 2020/3/25 21:47
 * @Version: 1.0
 */
@Controller
public class SpeculumExamineItemController {
    @Resource
    private SpeculumExamineItemService speculumExamineItemService;

    @ResponseBody
    @RequestMapping("/getSpeExamineItems")
    public DataPage getSpeExamineItems(int currentPageNum, int pageSize){
        Session session= SecurityUtils.getSubject().getSession();
        Examiner examiner=(Examiner)((PrincipalCollection)session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)).getPrimaryPrincipal();
        DataPage dataPage=speculumExamineItemService.getSpeculumExamineItemList(examiner.getUnitId(), currentPageNum, pageSize);
        return dataPage;
    }

    @ResponseBody
    @RequestMapping("/submitAddSpeExamineItem")
    public ResponseResult submitAddSpeExamineItem(SpeculumExamineItem speculumExamineItem){
        Session session= SecurityUtils.getSubject().getSession();
        Examiner examiner=(Examiner)((PrincipalCollection)session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)).getPrimaryPrincipal();
        speculumExamineItem.setUnitId(examiner.getUnitId());
        ResponseResult responseResult=speculumExamineItemService.addSpeExamineItem(speculumExamineItem);
        return responseResult;
    }

    @ResponseBody
    @RequestMapping("/deleteSpeItemById")
    public ResponseResult deletespeItemById(Integer examineItemId){
        ResponseResult responseResult=speculumExamineItemService.deleteSpeItemById(examineItemId);
        return responseResult;
    }

    @ResponseBody
    @RequestMapping("/getAllSpeItems")
    public List<SpeculumExamineItem> getAllSpeItems(){
        Session session= SecurityUtils.getSubject().getSession();
        Examiner examiner=(Examiner)((PrincipalCollection)session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)).getPrimaryPrincipal();
        List<SpeculumExamineItem> speculumExamineItemList=speculumExamineItemService.getAllSpeItems(examiner.getUnitId());
        return speculumExamineItemList;
    }

    /*//临时
    @ResponseBody
    @RequestMapping("/submitSpeClauseValue")
    public ResponseResult submitSpeClauseValue(){
        ResponseResult responseResult=new ResponseResult();
        responseResult.setCode(1);
        return responseResult;
    }*/
}
